package com.wontube.smr.remote.web;

import java.util.Date;
import java.util.UUID;

import com.wontube.client.modle.vo.PagenateInfo;
import com.wontube.core.annotation.CacheSupport;
import com.wontube.core.annotation.NoLoginSupport;
import com.wontube.core.cache.Cacher;
import com.wontube.core.pub.servlet.handlers.BasicHandler;
import com.wontube.smr.dao.bo.FeedbackDao;
import com.wontube.smr.web.client.IFeedbackHandler;
import com.wontube.smr.web.client.model.po.Feedback;
import com.wontube.smr.web.client.model.vo.FeedbackItems;

/**
 * 
 * @author tanggf(2012-5-7)
 *
 */
@NoLoginSupport
public class FeedbackHandler extends BasicHandler implements IFeedbackHandler {

	@Override
	@CacheSupport
	public FeedbackItems listFeedbacks(PagenateInfo pageInfo, Integer feedbackType) {
		return FeedbackDao.selectValidFeedbacks(pageInfo,feedbackType);
	}

	@Override
	public int postFeedback(Feedback feedback) {
		feedback.setId(UUID.randomUUID().toString());
		feedback.setCreated(new Date());
		feedback.setStatus(Feedback.STATUS_NORMAL);
		
		int aff = FeedbackDao.insertFeedback(feedback);
		if(aff == 1){
			//release caches
			deleteAllFeedbackCaches();
		}
		return aff;
	}
	
	private void deleteAllFeedbackCaches(){
		String clazzName = IFeedbackHandler.class.getName();
		String methodName = "listFeedbacks";
		Cacher.defaultCacher.deleteAllCache(clazzName, methodName, 2);
	}	
}
